tools: add BablPolynomial test to trc-validator.c
authorEll <ell_se@yahoo.com>
Sun, 10 Sep 2017 17:33:41 +0000 (13:33 -0400)
committerEll <ell_se@yahoo.com>
Mon, 11 Sep 2017 11:32:25 +0000 (07:32 -0400)
tools/trc-validator.c

index c8663a9834b26315b5ede9e2601ab573b44a3935..fffbe946dfc945a78d0625fc9252c3b20d50534a 100644 (file)
@@ -1,13 +1,16 @@
-// utility program for validating lolremez approximation constants for TRCs
+// utility program for validating lolremez approximation constants, and
+// BablPolynomial based approximations, for TRCs
 // the currently used apprimxations for 1.8 and 2.2 gamma pow functions are
 // validated to be loss-less when coded for 8bit.
 
+#include "config.h"
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <math.h>
+#include "babl-internal.h"
 
-#if 1
+#if 0
 
 #define GAMMA 2.2
 
@@ -130,6 +133,43 @@ static inline float to_linear (float x)
 }
 #endif
 
+#if 1
+
+#define GAMMA  2.2
+#define X0     (  0.5f / 255.0f)
+#define X1     (254.5f / 255.0f)
+#define DEGREE 6
+#define SCALE  2
+
+static inline float from_linear (float x)
+{
+  if (x >= X0 && x <= X1)
+  {
+    BablPolynomial poly;
+
+    babl_polynomial_approximate_gamma (&poly,
+                                       1.0 / GAMMA, X0, X1, DEGREE, SCALE);
+
+    return babl_polynomial_eval (&poly, x);
+  }
+  return powf (x, 1.0f/GAMMA);
+}
+
+static inline float to_linear (float x)
+{
+  if (x >= X0 && x <= X1)
+  {
+    BablPolynomial poly;
+
+    babl_polynomial_approximate_gamma (&poly,
+                                       GAMMA, X0, X1, DEGREE, SCALE);
+
+    return babl_polynomial_eval (&poly, x);
+  }
+  return powf (x, GAMMA);
+}
+#endif
+
 static inline float from_linear_ref (float x)
 {
   return powf (x, 1.0/GAMMA);